import Login from "../pages/login/Login"
import NotFound from "../pages/notFound/NotFound"
import Role from "../pages/role/Role"
import Permisssion from "../pages/permission/Permisssion"
import Users from "../pages/users/Users"
import Home from "../pages/home/Home"
import Layout from "../layout/Layout"
import { Navigate } from "react-router-dom"
import Questions from "../pages/questions/Questions"
import CreateQuestions from "../pages/createquestions/CreateQuestions"
import PermissionRoute from "./PermissionRoute"
import Forbidden from "../pages/403/Forbidden"

const routes = [
  // 首页
  {
    path: "/",
    element: <Home />,
    layout:true
  },
  // 系统管理
  {
    path: "/userManage",
    element: <Navigate to="/userManage/manage-page" />
  },
  // 用户管理
  {
    path: "/userManage/manage-page",
    element: <Users />,
    layout:true,
    permission:true
  },
  // 权限管理
  {
    path: "/userManage/menuManage",
    element: <Permisssion />,
    layout:true,
    permission:true
  },
  // 角色管理
  {
    path: "/userManage/system",
    element: <Role/>,
    layout:true,
    permission:true
  },
  // 试题管理
  {
    path:"/question",
    element:<Navigate to="/question/item-bank" />,
  },
  // 题库
  {
    path:"/question/item-bank",
    element:<Questions />,
    layout:true,
    permission:true
  },
  // 创建试题
  {
    path:"/question/create-item",
    element:<CreateQuestions />,
    layout:true,
    permission:true
  },
  // 登录
  {
    path: "/user/login",
    element: <Login />
  },
  // 403
  {
    path: "/403",
    element: <Forbidden />
  },
  // 404
  {
    path: "*",
    element: <NotFound />
  },

]


export default routes.map(route =>{
  if(route.layout) {
    route.element = <Layout>{route.element}</Layout>
  }
  if(route.permission) {
    route.element = <PermissionRoute>{route.element}</PermissionRoute>
  }
  return route
})





